#!/bin/bash

VER=$1
SOU=client_$VER
TAG=$SOU.tar.gz

SETUP_DIR="~/deploy/client"

tar cjf $TAG ./$SOU

SETUP=./update.$VER.sh

cat > $SETUP <<EOF
#!/bin/bash

mkdir -p $SETUP_DIR
rm -rf $SETUP_DIR/$SOU $SETUP_DIR/$TAG
cp ./$TAG $SETUP_DIR

cd $SETUP_DIR

echo "======extracting: $TAG"

tar xf ./$TAG
cd $SOU

cd front

./update
EOF

chmod +x $SETUP

rm -rf ~/$SOU
mkdir -p ~/$SOU

cp $TAG $SETUP ~/$SOU
hostname -I
